//
//  SCHotTravelCollectionViewCell.m
//  LastOne
//
//  Created by dllo on 15/11/7.
//  Copyright © 2015年 sc. All rights reserved.
//

#import "SCHotTravelCollectionViewCell.h"
#import <UIImageView+WebCache.h>
#import "NightHeader.h"
#import "FitHeader.h"
@implementation SCHotTravelCollectionViewCell

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        _imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height - 50 * FitHeight)];
        [self addSubview:_imageView];
        
        _numberLabel = [[UILabel alloc] init];
        _numberLabel.textAlignment = 1;
        _numberLabel.textColor = [UIColor whiteColor];
        _numberLabel.backgroundColor = [UIColor blackColor];
        _numberLabel.alpha = 0.3;
        _numberLabel.font = [UIFont systemFontOfSize:24 * FitWidth];
        [self addSubview:_numberLabel];
        
        _typeLabel = [[UILabel alloc] init];
        _typeLabel.textAlignment = 1;
        _typeLabel.font = [UIFont systemFontOfSize:13 * FitWidth];
        _typeLabel.backgroundColor = [UIColor blackColor];
        _typeLabel.alpha = 0.3;
        _typeLabel.textColor = [UIColor whiteColor];
        [self addSubview:_typeLabel];
        
        _backView = [[UIView alloc] initWithFrame:CGRectMake(0, frame.size.height - 50 * FitWidth, frame.size.width, 50 * FitHeight)];
        _backView.backgroundColor = [UIColor darkGrayColor];
        [self addSubview:_backView];
        
        _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, frame.size.height - 50 * FitWidth, frame.size.width, 30 * FitHeight)];
        _nameLabel.backgroundColor = [UIColor blackColor];
        _nameLabel.alpha = 0.3;
        _nameLabel.textColor = [UIColor whiteColor];
        _nameLabel.font = [UIFont systemFontOfSize:20 * FitWidth];
        [self addSubview:_nameLabel];
        
        _ennameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, _nameLabel.frame.origin.y + _nameLabel.frame.size.height, _nameLabel.frame.size.width, 20 * FitHeight)];
        _ennameLabel.backgroundColor = [UIColor blackColor];
        _ennameLabel.alpha = 0.3;
        _ennameLabel.textColor = [UIColor whiteColor];
        _ennameLabel.font = [UIFont systemFontOfSize:13 * FitWidth];
        [self addSubview:_ennameLabel];
    }
    return self;
}

-(void)setCity:(SCDesCity *)city
{
    if (_city != city) {
        _city = city;
    }
    
    [_imageView sd_setImageWithURL:[NSURL URLWithString:city.photo] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    _numberLabel.text = [NSString stringWithFormat:@"%ld", city.count];
    NSInteger number = city.count;
    NSInteger digit = 1;
    do {
        number /= 10;
        digit++;
    } while (number >= 10);
    //    NSLog(@"%ld", 10 + 15 * digit);
    _numberLabel.frame = CGRectMake(self.frame.size.width - 5 * FitWidth - 10  * FitWidth - 15  * FitWidth * digit, 5, 10  * FitWidth + 15  * FitWidth * digit, 40 * FitHeight);
    _typeLabel.frame = CGRectMake(_numberLabel.frame.origin.x, _numberLabel.frame.origin.y + _numberLabel.frame.size.height, _numberLabel.frame.size.width, 25 * FitHeight);
    
    _typeLabel.text = city.label;
    _nameLabel.text = city.cnname;
    _ennameLabel.text = city.enname;
}

@end
